home *** CD-ROM | disk | FTP | other *** search
/ HPAVC / HPAVC CD-ROM.iso / MOR55SRC.ZIP / MORIA / SOURCE / MAGIC.C < prev    next >
C/C++ Source or Header  |  1992-12-07  |  5KB  |  217 lines

  1. /* source/magic.c: code for mage spells
  2.  
  3.    Copyright (c) 1989-92 James E. Wilson, Robert A. Koeneke
  4.  
  5.    This software may be copied and distributed for educational, research, and
  6.    not for profit purposes provided that this copyright and statement are
  7.    included in all such copies. */
  8.  
  9. #include "config.h"
  10. #include "constant.h"
  11. #include "types.h"
  12. #include "externs.h"
  13.  
  14.  
  15. /* Throw a magic spell                    -RAK-    */
  16. void cast()
  17. {
  18.   int i, j, item_val, dir;
  19.   int choice, chance, result;
  20.   register struct flags *f_ptr;
  21.   register struct misc *p_ptr;
  22.   register inven_type *i_ptr;
  23.   register spell_type *m_ptr;
  24. #ifdef ATARIST_MWC
  25.   int32u holder;
  26. #endif
  27.  
  28.   free_turn_flag = TRUE;
  29.   if (py.flags.blind > 0)
  30.     msg_print("You can't see to read your spell book!");
  31.   else if (no_light())
  32.     msg_print("You have no light to read by.");
  33.   else if (py.flags.confused > 0)
  34.     msg_print("You are too confused.");
  35.   else if (class[py.misc.pclass].spell != MAGE)
  36.     msg_print("You can't cast spells!");
  37.   else if (!find_range(TV_MAGIC_BOOK, TV_NEVER, &i, &j))
  38.     msg_print("But you are not carrying any spell-books!");
  39.   else if (get_item(&item_val, "Use which spell-book?", i, j, CNIL, CNIL))
  40.     {
  41.       result = cast_spell("Cast which spell?", item_val, &choice, &chance);
  42.       if (result < 0)
  43.     msg_print("You don't know any spells in that book.");
  44.       else if (result > 0)
  45.     {
  46.       m_ptr = &magic_spell[py.misc.pclass-1][choice];
  47.       free_turn_flag = FALSE;
  48.  
  49.       if (randint(100) < chance)
  50.         msg_print("You failed to get the spell off!");
  51.       else
  52.         {
  53.           /* Spells.  */
  54.           switch(choice+1)
  55.         {
  56.         case 1:
  57.           if (get_dir(CNIL, &dir))
  58.             fire_bolt(GF_MAGIC_MISSILE, dir, char_row, char_col,
  59.                   damroll(2, 6), spell_names[0]);
  60.           break;
  61.         case 2:
  62.           (void) detect_monsters();
  63.           break;
  64.         case 3:
  65.           teleport(10);
  66.           break;
  67.         case 4:
  68.           (void) light_area(char_row, char_col);
  69.           break;
  70.         case 5:
  71.           (void) hp_player(damroll(4, 4));
  72.           break;
  73.         case 6:
  74.           (void) detect_sdoor();
  75.           (void) detect_trap();
  76.           break;
  77.         case 7:
  78.           if (get_dir(CNIL, &dir))
  79.             fire_ball(GF_POISON_GAS, dir, char_row, char_col, 12,
  80.                   spell_names[6]);
  81.           break;
  82.         case 8:
  83.           if (get_dir(CNIL, &dir))
  84.             (void) confuse_monster(dir, char_row, char_col);
  85.           break;
  86.         case 9:
  87.           if (get_dir(CNIL, &dir))
  88.             fire_bolt(GF_LIGHTNING, dir, char_row, char_col,
  89.                   damroll(4, 8), spell_names[8]);
  90.           break;
  91.         case 10:
  92.           (void) td_destroy();
  93.           break;
  94.         case 11:
  95.           if (get_dir(CNIL, &dir))
  96.             (void) sleep_monster(dir, char_row, char_col);
  97.           break;
  98.         case 12:
  99.           (void) cure_poison();
  100.           break;
  101.         case 13:
  102.           teleport((int)(py.misc.lev*5));
  103.           break;
  104.         case 14:
  105.           for (i = 22; i < INVEN_ARRAY_SIZE; i++)
  106.             {
  107.               i_ptr = &inventory[i];
  108. #ifdef ATARIST_MWC
  109.               i_ptr->flags = (i_ptr->flags & ~(holder = TR_CURSED));
  110. #else
  111.               i_ptr->flags = (i_ptr->flags & ~TR_CURSED);
  112. #endif
  113.             }
  114.           break;
  115.         case 15:
  116.           if (get_dir(CNIL, &dir))
  117.             fire_bolt(GF_FROST, dir, char_row, char_col,
  118.                   damroll(6, 8), spell_names[14]);
  119.           break;
  120.         case 16:
  121.           if (get_dir(CNIL, &dir))
  122.             (void) wall_to_mud(dir, char_row, char_col);
  123.           break;
  124.         case 17:
  125.           create_food();
  126.           break;
  127.         case 18:
  128.           (void) recharge(20);
  129.           break;
  130.         case 19:
  131.           (void) sleep_monsters1(char_row, char_col);
  132.           break;
  133.         case 20:
  134.           if (get_dir(CNIL, &dir))
  135.             (void) poly_monster(dir, char_row, char_col);
  136.           break;
  137.         case 21:
  138.           (void) ident_spell();
  139.           break;
  140.         case 22:
  141.           (void) sleep_monsters2();
  142.           break;
  143.         case 23:
  144.           if (get_dir(CNIL, &dir))
  145.             fire_bolt(GF_FIRE, dir, char_row, char_col,
  146.                   damroll(9, 8), spell_names[22]);
  147.           break;
  148.         case 24:
  149.           if (get_dir(CNIL, &dir))
  150.             (void)speed_monster(dir, char_row, char_col, -1);
  151.           break;
  152.         case 25:
  153.           if (get_dir(CNIL, &dir))
  154.             fire_ball(GF_FROST, dir, char_row, char_col, 48,
  155.                   spell_names[24]);
  156.           break;
  157.         case 26:
  158.           (void) recharge(60);
  159.           break;
  160.         case 27:
  161.           if (get_dir(CNIL, &dir))
  162.             (void) teleport_monster(dir, char_row, char_col);
  163.           break;
  164.         case 28:
  165.           f_ptr = &py.flags;
  166.           f_ptr->fast += randint(20) + py.misc.lev;
  167.           break;
  168.         case 29:
  169.           if (get_dir(CNIL, &dir))
  170.             fire_ball(GF_FIRE, dir, char_row, char_col, 72,
  171.                   spell_names[28]);
  172.           break;
  173.         case 30:
  174.           destroy_area(char_row, char_col);
  175.           break;
  176.         case 31:
  177.           (void) genocide();
  178.           break;
  179.         default:
  180.           break;
  181.         }
  182.           /* End of spells.                     */
  183.           if (!free_turn_flag)
  184.         {
  185.           p_ptr = &py.misc;
  186.           if ((spell_worked & (1L << choice)) == 0)
  187.             {
  188.               p_ptr->exp += m_ptr->sexp << 2;
  189.               spell_worked |= (1L << choice);
  190.               prt_experience();
  191.             }
  192.         }
  193.         }
  194.       p_ptr = &py.misc;
  195.       if (!free_turn_flag)
  196.         {
  197.           if (m_ptr->smana > p_ptr->cmana)
  198.         {
  199.           msg_print("You faint from the effort!");
  200.           py.flags.paralysis =
  201.             randint((int)(5*(m_ptr->smana-p_ptr->cmana)));
  202.           p_ptr->cmana = 0;
  203.           p_ptr->cmana_frac = 0;
  204.           if (randint(3) == 1)
  205.             {
  206.               msg_print("You have damaged your health!");
  207.               (void) dec_stat (A_CON);
  208.             }
  209.         }
  210.           else
  211.         p_ptr->cmana -= m_ptr->smana;
  212.           prt_cmana();
  213.         }
  214.     }
  215.     }
  216. }
  217.